﻿using CMS.BaseEntity;
using CMS.BusinessLogic;
using CMS.Common;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CMS.UserControl
{
    public partial class DeleteProduct : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.QueryString["pid"] != null)
                {
                    BindDetailToDelete();
                }
            }
        }

        ProductLogic pLogic = new ProductLogic();

        protected void BindDetailToDelete()
        {
            Product product = new Product();
            product.ProductId = int.Parse(Request.QueryString["pid"].ToString());
            DataTable dt = pLogic.GetById(product);
            grvProduct.DataSource = dt;
            grvProduct.DataBind();
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            Product product = new Product();
            product.ProductId = int.Parse(Request.QueryString["pid"].ToString());
            if (pLogic.IsDeleted(product))
            {
                //ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "alert", Script.Manipulate_Success, true);                
                Response.Redirect("ChannelProduct.aspx?component=prdupdate");
            }
            else
                ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "alert", Script.Manipulate_Fail, true);
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("ChannelProduct.aspx?component=prdupdate");
        }
    }
}